clear all
set more off 

cd "D:\data\MoscowMayorElections\RAW_DATA"

log close _all


set more off
clear matrix
clear mata
clear




use data_moscow_elections_Jan2024





mat Table2=J(40,8,0)






*for the main analysis we include only stations which had non-zero probability to be included in treatment, specifically we exclude transport hubs and short lines

g incl=(station_hub==0)&(metrolinepairs>0)

keep if incl==1

loc Table2vars="percent_putin percent_sobyanin percent_melnikov percent_degtyarev percent_levichev percent_mitrokhin percent_navalny percent_turnout2013 percent_invalid"


* here we prepare output for Table 2. Summary statistics and the differences between control and treatment samples, errors are clustered by metro pair lines
sca s_i=0
foreach var_i in `Table2vars' {

sca s_i=s_i+1

	forvalues s_j = 1/4 {
forvalues s_k = 1/2 {
	if `s_k'==1 {
	su `var_i' if newspaper==0 & col`s_j', detail
	mat Table2[s_i*4-3,`s_j'*2-1]=r(mean)
	mat Table2[s_i*4-2,`s_j'*2-1]=r(sd)

	}
	else {
	su `var_i' if newspaper==1 & col`s_j', detail
	mat Table2[s_i*4-1,`s_j'*2-1]=r(mean)
	mat Table2[s_i*4,`s_j'*2-1]=r(sd)

	}
	
	mat Table2[38+`s_k',`s_j'*2-1]=r(N)
		
    }  
	reg `var_i' newspaper if col`s_j', cl(metrolinepairs)
    mat b=e(b)
    mat V=e(V)
	
	mat Table2[s_i*4-3,`s_j'*2]=b[1,1]
    mat Table2[s_i*4-2,`s_j'*2]=b[1,1]/sqrt(V[1,1])

 }

      
 }


mat list Table2
set more on
more
set more off

* here we prepare output for Table 3. Regression of votes for Putin in presidential election 2012 and treatment

loc var_y="percent_putin"
mat Table3=J(10,4,0)

	
	forvalues s_j = 1/4 {
	reg `var_y' newspaper distmetro percent_turnout2012 if col`s_j' `var_cl', cl(metrolinepairs)
	
mat b=e(b)
mat V=e(V)

	forvalues s_k = 1/4 {
mat Table3[`s_k'*2-1,`s_j']=b[1,`s_k']
mat Table3[`s_k'*2,`s_j']=b[1,`s_k']/sqrt(V[`s_k',`s_k'])
}

	mat Table3[9,`s_j']=e(r2)
	mat Table3[10,`s_j']=e(N)
	
    }
      


mat list Table3
set more on
more
set more off







loc var_y="percent_sobyanin newspaper percent_putin percent_turnout2012 distmetro"

* here we prepare output for Table 4. Regression of votes for Sobyanin in Moscow mayor election 2013 and treatment



mat Table4=J(10,4,0)

	
	forvalues s_j = 1/4 {
	reg `var_y'  if col`s_j', cl(metrolinepairs)
		
mat b=e(b)
mat V=e(V)

	forvalues s_k = 1/4 {
mat Table4[`s_k'*2-1,`s_j']=b[1,`s_k']
mat Table4[`s_k'*2,`s_j']=b[1,`s_k']/sqrt(V[`s_k',`s_k'])
}

	mat Table4[9,`s_j']=e(r2)
	mat Table4[10,`s_j']=e(N)
	
    }
      


mat list Table4
set more on
more
set more off

* here we prepare output for Table 5a and 5b. Regression of votes for different election outcomes in Moscow mayor election 2013 and treatment




foreach var_col of varlist col1 col4 { 
mat Table5=J(22,7,0)

loc vars="newspaper percent_putin percent_turnout2012 distmetro"
	
	forvalues s_j = 1/7 {
if `s_j'==1 reg percent_melnikov `vars' percent_zu if `var_col', cl(metrolinepairs)
	if `s_j'==2 reg percent_degtyarev `vars' percent_zhir if `var_col', cl(metrolinepairs)
if `s_j'==3 reg percent_levichev `vars' percent_mir if `var_col', cl(metrolinepairs)
if `s_j'==4 reg percent_mitrokhin `vars' percent_proh if `var_col', cl(metrolinepairs)
if `s_j'==5 reg percent_navalny `vars' percent_proh if `var_col', cl(metrolinepairs)
if `s_j'==6 reg percent_turnout2013 `vars'  if `var_col', cl(metrolinepairs) 
if `s_j'==7 reg percent_invalid `vars' if `var_col', cl(metrolinepairs)
	
mat b=e(b)
mat V=e(V)

	forvalues s_k = 1/8 {
mat Table5[`s_k'*2-1,`s_j']=b[1,`s_k']
mat Table5[`s_k'*2,`s_j']=b[1,`s_k']/sqrt(V[`s_k',`s_k'])
}

	mat Table5[21,`s_j']=e(r2)
	mat Table5[22,`s_j']=e(N)
	
    }
      


mat list Table5
set more on
more
set more off

}





